package br.com.tbp.gui.table;

import br.com.tbp.model.domain.financeiro.AjudaCusto;
import br.com.tbp.model.domain.financeiro.StatusAjuda;
import br.com.tbp.utils.ColorUtils;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

/**   
 * Our own Table Cell Renderer.  It also paints every other line of the table
 * a slightly darker offset of the base color, which for white gives a nice
 * white and gray effect.
 * @author EAL April 2001
 * @version 1.0.0
 */
public class AjudaCustoTableRenderer extends DefaultTableCellRenderer {

    /**
     * Override this method from the parent class.
     * Only paint the background if the row isn't selected
     * Paint every other row a color very similiar to the base color, just a little
     * darker
     * @param table the JTable component
     * @param value the cell content's object
     * @param isSelected boolean so we know if this is the currently selected row
     * @param hasFocus does this cell currently have focus?
     * @param row the row number
     * @param column the column number
     */
    @Override
    public Component getTableCellRendererComponent(JTable table, java.lang.Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if (!isSelected) {
            AjudaCusto ajuda = ((AjudaCustoTableModel) table.getModel()).getAjudaCusto(row);
            if (ajuda != null) {
                if (ajuda.getStatus().equals(StatusAjuda.PENDENTE)) {
                    setBackground(ColorUtils.getVermelhoClaro());
                } else if (ajuda.getStatus().equals(StatusAjuda.QUITADA)) {
                    setBackground(ColorUtils.getVerdeClaro());
                }
            }
        } else {
            setBackground(Color.WHITE);
        }
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}
